import 'dart:async';

import 'package:get/get.dart';
import 'package:ball_lion/entity/live/live_statistics_entity.dart';

import 'package:ball_lion/server/api/live_api.dart';

class LiveStatisticsLogic extends GetxController {
  int? liveId = Get.arguments;
  LiveStatisticsEntity? statistics;
  Timer? timer;

  @override
  void onReady() {
    getData();
    timer = Timer.periodic(const Duration(seconds: 2), (timer) {
      getData();
    });
    super.onReady();
  }

  Future getData() async {
    statistics = await LiveApi.getStatistics(liveId);
    update();
  }

  @override
  void onClose() {
    timer?.cancel();
    super.onClose();
  }
}
